package com.mdlib.helper.model;


import com.mdlib.helper.model.entity.AccountInfo;
import com.mdlib.helper.utils.MDAppUtils;

import java.io.Serializable;

/**
 * 作者：HQY on 16/8/20 15:25
 * 邮箱：hqy_xz@126.com
 */
public class AccountModel implements Serializable, Cloneable {

    public static final String TAG = "account_object";

    private static final long serialVersionUID = 1L;


    private static AccountModel instance;

    private boolean isLogin;


    private int loginType;   // 与账户类型相同


    // 本地登录， 用户名 密码
    private String loginName;
    private String loginPwd;

    //角色
    private String roleType;

    // 第三方登录
    private int thirdType;   // "qq"  "weixin"
    private String thirdUid;    // 三方登录唯一标识

    // 登录后sessionId
    private String sessionId;


    // 登录IM的账号和签名
    private String tencentUid;
    private String tencentSign;

    //    消息开关(跑客)
    private String system;
    private String rules;

    public static AccountModel getInstance() {
        if (instance == null) {
            synchronized (AccountModel.class) {
                Object object = MDAppUtils.restoreObject(TAG);
                if (object == null) {
                    object = new AccountModel();
                    MDAppUtils.saveObject(TAG, object);
                }

                instance = (AccountModel) object;
            }
        }
        return instance;
    }


    public void writeToCache() {
        MDAppUtils.saveObject(TAG, this);
    }

    public void reset() {
        clearData();
        MDAppUtils.saveObject(TAG, this);
    }

    public void clearCache() {
        clearData();
        MDAppUtils.saveObject(TAG, this);
    }

    private void clearData() {
        isLogin = false;
        loginType = 0;
        loginName = null;
        loginPwd = null;
        thirdType = 0;
        thirdUid = null;
        sessionId = null;
        tencentUid = null;
        tencentSign = null;
        roleType = null;
        system = null;
        rules = null;
    }


    public void setAccountInfo(AccountInfo accountInfo) {

    }


    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getLoginPwd() {
        return loginPwd;
    }

    public void setLoginPwd(String loginPwd) {
        this.loginPwd = loginPwd;
    }

    public boolean isLogin() {
        return isLogin;
    }

    public void setLogin(boolean isLogin) {
        this.isLogin = isLogin;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public int getLoginType() {
        return loginType;
    }

    public void setLoginType(int loginType) {
        this.loginType = loginType;
    }

    public int getThirdType() {
        return thirdType;
    }

    public void setThirdType(int thirdType) {
        this.thirdType = thirdType;
    }

    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    public static void setInstance(AccountModel instance) {
        AccountModel.instance = instance;
    }


    public String getThirdUid() {
        return thirdUid;
    }

    public void setThirdUid(String thirdUid) {
        this.thirdUid = thirdUid;
    }

    public String getTencentUid() {
        return tencentUid;
    }

    public void setTencentUid(String tencentUid) {
        this.tencentUid = tencentUid;
    }

    public String getTencentSign() {
        return tencentSign;
    }

    public void setTencentSign(String tencentSign) {
        this.tencentSign = tencentSign;
    }

    public String getSystem() {
        return system;
    }

    public void setSystem(String system) {
        this.system = system;
    }

    public String getRules() {
        return rules;
    }

    public void setRules(String rules) {
        this.rules = rules;
    }
}
